<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>发布动态</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" type="text/css" href="../../css/sm.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/normal.css" />
    <link rel="stylesheet" type="text/css" href="../../css/release.css" />
    <link rel="stylesheet" type="text/css" href="../../css/globle.css">
</head>

<body>
    <div class="page allWarp">
        <div class="content">
            <div class="releaseContent">
                <textarea name="release" placeholder="描述任务完成情况" v-model="description"></textarea>
                <div class="picList">
                    <div class="imgUpload">
                        <p class="colgreen font12 col666" style="padding-bottom: 0.625rem">*请上传图片(最多6张)</p>
                        <ul class="upload-ul clearfix">
                            <li class="upload-pick">
                                <div class="webuploader-container clearfix" id="goodsUpload"></div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="pushDt" onclick="reUploads()">发布动态</div>
        </div>
    </div>
    <script type='text/javascript' src='../../js/jquery-3.1.0.min.js'></script>
    <script type="text/javascript" src="../../js/webuploader.min.js"></script>
    <script type="text/javascript" src="../../js/diyUpload.js"></script>
    <script type="text/javascript" src="../../js/back.js"></script>
    <script>
    jQuery.noConflict()
    jQuery(function() {
        //上传图片
        var $tgaUpload = jQuery('#goodsUpload').diyUpload({
            url: basurl + 'file/uploadOne',
            success: function(data) {
                demo.posImages.push([data.data.fileName, data.data.fileId]);
                if (demo.posImages.length >= 6) {
                    $(".upload-pick").css("display", "none")
                }

            },
            error: function(err) {
                console.log('上传失败');
            },
            buttonText: '',
            accept: {
                title: "Images",
                extensions: 'gif,jpg,jpeg,bmp,png'
            },
            thumb: {
                width: 120,
                height: 90,
                quality: 100,
                allowMagnify: false,
                crop: true,
                type: "image/jpeg"
            },
            fileNumLimit: 6,
        });
        $tgaUpload.on('fileQueued', function(file) {
            demo.ImagesNum++;
            // 移除监听
            $tgaUpload.on('fileDequeued', function(block) {
                for (var i = 0; i < demo.posImages.length; i++) {
                    if (demo.posImages[i][0] == block.name) {
                        demo.posImages.splice(i, 1)
                        demo.ImagesNum--;
                    }
                    if (demo.posImages.length < 6) {
                        $(".upload-pick").css("display", "block")
                    }
                };
            });
            // 加载监听
            $tgaUpload.on('uploadBeforeSend', function(block, data) {
                // block为分块数据。
                console.log(block);
                // file为分块对应的file对象。  
                var file = block.file;
                // 修改data可以控制发送哪些携带数据。  
                data.createUser = '1';
            });
            $tgaUpload.upload();
        });
    });
    </script>
    <script type="text/javascript" src="../../js/zepto.js"></script>
    <script type="text/javascript" src="../../js/sm.min.js"></script>
    <script type="text/javascript" src="../../js/vue.min.js"></script>
    <script type="text/javascript" src="../../js/ajax.js"></script>
    <script type="text/javascript">
        var keyN = JSON.parse(getCookie("user_data_three"));
        var createUser;
        if (keyN != null) {
            createUser = keyN.userId;
        }
        var nodeCode = GetQueryString("nodeCode");
        var demo = new Vue({
            el: '.allWarp',
            data: {
                posImages: [],
                description: '',
                isClick:true,
                ImagesNum:0,
            },
            beforeCreate: function() {
                // init();
            }
        })
        // 提交
        function reUploads() {
            var params = {};
            params.nodeCode = nodeCode;
            params.description = demo.description;
            params.fileIds = '';
            if (demo.posImages.length == 0) {
                $.alert('至少上传1张图片');
                return;
            }
            if(demo.ImagesNum != demo.posImages.length){
                $.alert('图片上传未完成');
                demo.isShow = 'true';
                return;
            }

            for (var i = 0; i < demo.posImages.length; i++) {
                if (i == 0) {
                    params.fileIds = demo.posImages[i][1]
                } else {
                    params.fileIds = params.fileIds + ',' + demo.posImages[i][1]
                }
            }
            params.createUser = createUser;
            if(!demo.isClick){
                return;
            }
            demo.isClick = false;
            $.showIndicator();
            kfAjaxGet.projectNodeLog(params, function(json) {
                $.hidePreloader();
                if (json.code == '200') {
                    history.go(-1);
                } else if (checkcode(json.code)) {
                    setTimeout(function () {
                        demo.isClick = true;
                        $.hideIndicator();
                    }, 2000);
                } else {
                    $.toast(json.message);
                    setTimeout(function () {
                        demo.isClick = true;
                        $.hideIndicator();
                    }, 2000);
                }
            });
        }
        $(function(){
            $('#gohome').on('click',function(){
                window.location = 'taskList.html';
            })
        })
    </script>
</body>
</html>